package com.cgbl.cg.ui.collection

import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.fastjson.JSON
import com.cgbl.cg.BR
import com.cgbl.cg.R
import com.cgbl.cg.adapter.CollectionsDetailsAdapter
import com.cgbl.cg.databinding.AppActivityCollectionsDetailsBinding
import com.cgbl.cg.vm.collection.CollectionsDetailsViewModel
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import com.robot.base.model.CollectDetailBean
import com.robot.base.model.CourseAllTypeBean
import com.robot.base.model.WorksBean

@Route(path = AppConstants.Router.COLLECTION.A_COLLECTIONS_DETAILS)
class CollectionsDetailsActivity :
    GLBaseActivity<AppActivityCollectionsDetailsBinding, CollectionsDetailsViewModel>() {
    private lateinit var collectionsDetailsAdapter: CollectionsDetailsAdapter
    var id = ""

    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_collections_details

    override fun initVariableId(): Int = BR.viewModel

    override fun initComponents() {
        addSingleTitleBar("", R.mipmap.app_ic_more)

        initAdapter()
    }

    override fun initParam() {
        super.initParam()
        id = intent.getStringExtra(AppConstants.BundleKey.COLLECTION_DATA) ?: ""
    }

    override fun initData() {
        super.initData()
        viewModel.getCollectDetail(id)
    }

    private fun initAdapter() {
        collectionsDetailsAdapter = CollectionsDetailsAdapter()
        binding.mRv.apply {
            adapter = collectionsDetailsAdapter
        }

    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uc.dataEvent.observe(this) {
            it ?: return@observe
            collectionsDetailsAdapter.setNewInstance(it as MutableList<WorksBean>?)
        }
    }

}